package com.example.dhhyc.demos.strategy.strategy2;

import org.springframework.util.StringUtils;

import java.util.HashMap;
import java.util.Map;

/**
 * Describe :
 * question :
 *
 * @auther BaiShanshan作者
 * @date 2024/5/2 8:15
 */

public class HandlerCalFactory {

    private static Map<String, CalHandler> handlerMap = new HashMap<String,CalHandler>();


    public static void register(String key, CalHandler calHandler){
        if(StringUtils.isEmpty(key) && null == calHandler){
            return;
        }
        handlerMap.put(key, calHandler);
    }

    public static CalHandler getInvokeHandler(String type) {
        if (StringUtils.isEmpty(type)) {
            throw new RuntimeException("type is null");
        }
        CalHandler abstractCalHandler= handlerMap.get(type);
        return abstractCalHandler;
    }


}
